/*
 * Created on Jan 24, 2005
 */
package org.vectrics.user.web.struts;

import java.util.Collection;
import java.util.Iterator;

import org.apache.ecs.html.Input;
import org.apache.log4j.Logger;
import org.vectrics.DataException;
import org.vectrics.SystemException;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.VectricsTagSupport;
import org.vectrics.user.Person;
import org.vectrics.user.UserPrivilegeType;

/**
 * @author MMoore
 */
abstract public class UserPrivilegesNotChangeableTag extends VectricsTagSupport {
	protected abstract Collection getRoles();
	private transient final Logger log = Logger.getLogger(this.getClass());
	private String personId = null;
	
	public UserPrivilegesNotChangeableTag() {
		super();
	}

	protected String makeStartTag() {
		StringBuffer html = new StringBuffer();

		
		Person authPerson = this.getAuthPerson();
    	Iterator iter = this.getRoles().iterator();
    	while (iter.hasNext()) {
    		UserPrivilegeType roleType = (UserPrivilegeType)iter.next();
    		
			if (false == CoreServiceLocator.getUserAuthService().hasRightToAssignPrivilege(authPerson, roleType)) {
				Input hiddenNoPrivIndicator = new Input();
				hiddenNoPrivIndicator.setType(Input.HIDDEN);
				String keyName = "no_priv_" + roleType.getCode(); 
				hiddenNoPrivIndicator.setName(keyName);
				hiddenNoPrivIndicator.setValue(keyName);
				html.append(hiddenNoPrivIndicator.toString());
			} 
    	}
		
		return html.toString();
	}

	
	/**
	 * @return Returns the personId.
	 */
	public String getPersonId() {
		return personId;
	}
	/**
	 * @param personId The personId to set.
	 */
	public void setPersonId(String personId) {
		this.personId = personId;
	}
}
